﻿using log4net.Layout;
using log4net.Config;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Log4netTestApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            LogHelper.ErrorLog(typeof(Form1), "测试");
        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            try
            {
                LogHelper.InfoLog(typeof(Form1), "测试1");

            }
            catch (Exception ex)
            { 
                
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string filePath = string.Concat(Application.StartupPath, "\\log4net.config");
            FileInfo fileInfo = new FileInfo(filePath);
            XmlConfigurator.ConfigureAndWatch(fileInfo);

            var logPattern = "%d{yyyy-MM-dd HH:mm:ss} --%-5p-- %m%n";
            var textBox_logAppender = new TextBoxBaseAppender()
            {
                TextBox = this.textBox1,//注释后 就只有文件log  
                Layout = new PatternLayout(logPattern)
            };
            //相当于root标签下的   <appender-ref ref="LogFile" />  
            log4net.Config.BasicConfigurator.Configure(textBox_logAppender);
        }
    }
}
